var Toast = require("./Toast.js");

var Utils = {
};

Utils.isAndroid = function () {
    return typeof (mz_jsb) != "undefined";
}

Utils.showMzGameToast = function (text) {
    Toast.showMzGameToast(text)
}

Utils.resetFrameFromNet =  function(sprite,url) {
    // if(!Utils.isAndroid()) {
    //     return;
    // }
    try {
        console.log("resetFrameFromNet url ="+ url);
        cc.loader.load({url: url, type:  "png" }, function (err, texture) {
            if (err) {
                cc.log(err);
            } else {
                var frame = new cc.SpriteFrame(texture);
                console.log("!!!!!resetFrameFromNet success !!!!!! sprite ="+ sprite);
                if(sprite != null && sprite.node != null) {
                    sprite.spriteFrame = frame;
                }
            }
        }.bind(this));
    } catch (error) {
        console.log("!!!!!resetFrameFromNet!!!!!! url ="+ url +" error = " +error);
    }
},


Utils.resetFrame = function(sprite,url) {
    cc.loader.loadRes(url, cc.SpriteFrame, function (err, spriteFrame) {
        if (err) {
            cc.log(err);
        } else {
            if(sprite != null && sprite.node != null) {
               sprite.spriteFrame = spriteFrame;
            }
        }
    }.bind(this));
},

module.exports = Utils;


